﻿using System;
using System.Collections.Generic;
using Battle.Engine.InputData;
using Battle.Engine.LogicModel;
using Battle.Engine.util;

namespace Battle.Engine
{
    public class EngineDefault
    {
        public BaseCompute compute = null;

        public bool run = false;                //是否工作
        public bool rounding = false;           //mxd 是否在回合中 

        //设置真实的战斗数据
        public void SetFightData(InFightData idata)
        {
            ComputeCore core = new ComputeCore();
            core.SetData(idata);
            this.compute = core;    
        }

        //设置AI,只对真实战斗有效
        public void SetAI(CampType camp, AI.EngineAI ai)
        {
            this.compute.SetAI(camp, ai);
        }

        //设置是否使用AI自动操作
        public void SetAuto(CampType camp, bool auto)
        {
            this.compute.SetAuto(camp, auto);
        }

        public bool IsAuto(CampType camp)
        {
            return this.compute.IsAuto(camp);
        }

        //设置战斗脚本数据
        public void SetScriptData()
        {

        }

        public void SetCallback(EngineCallback callback)
        {
            this.compute.SetCallback(callback);
        }

        //开始
        public void Start()
        {
            run = true;
            rounding = false;

            this.compute.Start();
        }

        //暂停
        public void Pause()
        {
            run = false;

            this.compute.Pause();
        }

        public void Continue() {
            run = true;
            this.compute.Continue();
            // TODO
        }

        //停止+释放资源
        public void Stop()
        {
            run = false;

            this.compute.Stop();
        }

        //跳过
        public void Skip()
        {
            this.compute.Skip();
        }

        //跳过大招
        public void SkipUltimate()
        {
            this.compute.SkipUltimate();
        }

        //获得释放技能和换阵的操作记录
        public void GetRecordOperates(CampType camp, out List<FOperateSkill> skills, out List<FOperateTrans> transs)
        {
            this.compute.GetRecordOperates(camp, out skills, out transs);
        }

        //设置
        public void SetReplayOperates(CampType camp, List<FOperateSkill> skills, List<FOperateTrans> transs)
        {
            this.compute.SetReplayOperates(camp, skills, transs);
        }

        //在非自动切换回合模式下,开始下一回合的接口
        public void NextRound()
        {
            rounding = true;
            this.compute.NextRound();
        }

        //回合结束
        public void FinishRound()
        {
            rounding = false;
            this.compute.FinishRound();
        }

        //使用技能
        public void DoSkill(CampType camp, string uniquedId, int index)
        {
            this.compute.DoSkill(camp, uniquedId, index);
        }

        //换阵
        public void DoTrans(List<string> uids, List<int> fpids)
        {
            this.compute.DoTrans(uids, fpids);
        }

        //每帧更新
        //@return 返回当前是否在回合内,调用完NextRound以后,如果返回不在回合内表示回合结束
        public void Update(double deltaTime)
        {
            if (!run)
                return;

            //执行compute逻辑
            this.compute.Update(deltaTime);
        }

        //设置技能开关
        public void SetSkill(CampType camp, string uniquedId, int skillIndex, bool enbale)
        {
            this.compute.SetSkill(camp, uniquedId, skillIndex, enbale);
        }

        public EngineData GetEngineData()
        {
            return this.compute.GetEngineData();
        }
    }
}
